# coding: utf8
# datetime: 2021-03-20
# 题目地址: https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/


from typing import  List


class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = [int(tokens[0])]
        for token in tokens[1:]:
            if token in "+-*/":
                num1 = stack.pop()
                num2 = stack.pop()
                stack.append(self.opera_num(num1, num2, token))
            else:
                stack.append(int(token))
        return stack[0]

    def opera_num(self, num1: int, num2: int, token: str) -> int:
        if token == "+":
            ret = num2+num1
        elif token == "-":
            ret = num2-num1
        elif token == "*":
            ret = num2*num1
        elif token == "/":
            ret = int(num2/num1)
        return ret


a = Solution()
print(a.evalRPN([
    "-78","-33","196","+","-19","-","115","+","-","-99","/","-18","8","*","-86","-","-",
    "16","/","26","-14","-","-","47","-","101","-","163","*","143","-","0","-","171","+",
    "120","*","-60","+","156","/","173","/","-24","11","+","21","/","*","44","*","180",
    "70","-40","-","*","86","132","-84","+","*","-","38","/","/","21","28","/","+","83",
    "/","-31","156","-","+","28","/","95","-","120","+","8","*","90","-","-94","*","-73",
    "/","-62","/","93","*","196","-","-59","+","187","-","143","/","-79","-89","+","-"
    ]))
            